package net.zjitc.demosecurity6.controller;


import net.zjitc.demosecurity6.pojo.User;
import net.zjitc.demosecurity6.service.UserService;
import net.zjitc.demosecurity6.utils.ApiResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author zhao
 * @DATE 2025/4/25 15:05
 */
@RestController
public class UserController {
  @Autowired
  private UserService userService;
    @PostMapping("/login")
    public ApiResponse login(@RequestBody User user) {
        String jwt = userService.login(user);
         ApiResponse apiResponse = new ApiResponse();
       if (jwt!=null){
           apiResponse.oK("登录成功",jwt);
           return apiResponse;

       }
        apiResponse.error(500,"登录失败",null);
       return apiResponse;

    }

}
